#ifndef QUSERMANAGERVIEW_H
#define QUSERMANAGERVIEW_H

#include <QWidget>

#include <QTreeWidget>
#include <QMap>
#include <QItemDelegate>

namespace CORELIB
{
    class StyledBar;
}

class QUserManagerView;

class QUserDelegate: public QItemDelegate
{
    Q_OBJECT
public :
    QUserDelegate(QUserManagerView* view):m_view(view){}
    QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;

protected:
    QUserManagerView    *m_view;
};

class QUserManagerView : public QWidget
{
    Q_OBJECT
public:
    explicit QUserManagerView(QWidget *parent = 0);

    bool    pagePosition(const QVariant& param);

    void    make_page_position(QVariant &info);
    void    set_page_position(const QVariant &info);
signals:
    void    need_make_page_position();
protected:
    void    addUserItem(QObject* obj);
    void    insertUserItem(QObject* obj,int index);

    void    updateNo();
    bool    eventFilter(QObject *o, QEvent *e);
signals:

public slots:
    void    cammand_rename();
    void    cammand_property();
protected slots:
    void    addUser();
    void    delUser();
    void    itemUp();
    void    itemDown();

    void    load();
    void    clear();

    void    cammand_add();
    void    cammand_remove();
protected:
    friend class QUserDelegate;
protected:
    QTreeWidget         *m_userList;
    CORELIB::StyledBar  *m_styledBar;
    QMap<QObject*,QTreeWidgetItem*>  m_items;
    QVariant            m_page_position;
};

#endif // QUSERMANAGERVIEW_H
